#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
void solve()
{
    int n;
    int q;
    cin >> n >> q;
    vector<ll> a(n + 10), dp(n + 10, 0);
    int i = 0;
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (i = 2; i < n; i++)
    {
        dp[i] += dp[i - 1];
        if (a[i - 1] <= a[i - 2] && a[i - 1] >= a[i])
            dp[i]++;
    }
    for (i = 0; i < q; i++)
    {
        ll l, r;
        cin >> l >> r;
        if (r - l == 1 || r - l == 0)
        {
            cout << r - l + 1 << endl;
        }
        else
        {
            cout << r - l + 1 - dp[r - 1] + dp[l] << endl;
        }
    }
}
int main()
{
    solve();

    return 0;
}
